package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Travel extends BaseDomain {

    public static final Integer TRAVEL_REFUSE = -1;
    public static final Integer TRAVEL_DRAFT = 0;
    public static final Integer TRAVEL_AUDIT = 1;
    public static final Integer TRAVEL_RELEASE = 2;


    private String title;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date travelTime;

    private String perExpends;

    private Integer days;

    private int person;

    private User author;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;

    private Boolean isPublic = false;

    private Region place;

    private String coverUrl;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date lastUpdateTime;

    private Integer state = TRAVEL_DRAFT;

    private TravelContent travelContent;


    private Integer praiseNum;//点赞总数
    private Integer browse;

    private Integer replyNum=0;

    public String getStateName(){
        String temp = "发布";
        if(state == TRAVEL_REFUSE){
            temp = "拒绝";
        }else if(state == TRAVEL_DRAFT){
            temp = "草稿";
        }else if(state == TRAVEL_AUDIT){
            temp = "待发布";
        }
        return temp;
    }

    public String  getPersonName(){
        String temp = "";
        switch (person){
            case 1:temp = "一个人的旅行";break;
            case 2:temp = "和父母";break;
            case 3:temp = "和朋友";break;
            case 4:temp="和同事";break;
            case 5:temp="和爱人";break;
            default:temp="和其他";
        }
        return temp;
    }

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("praiseNum",praiseNum);
        return JSONUtils.toJSONString(map);
    }

}